package com.softer.chengxin.project.dao;

import com.softer.chengxin.common.domin.Common;
import com.softer.chengxin.project.domin.ProfitVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

/**
 * @author Gong Zhiyang
 * @date 2018/10/17
 */
@Mapper
@Repository
public interface FeeDao {
    /**
     * 查询该项目当前年度具体信息
     *
     * @param projectId 项目ID
     * @return projectId
     */
    @Select("SELECT id,main_business_income as mainBusinessIncome,public_income as publicIncome,profit,`year`,project_id as projectId,multi_storey_area as multiStoreyArea," +
            "IFNULL(multi_storey_buildingNum,0) as multiStoreyBuildingNum, IFNULL(multi_storey_households,0) as multiStoreyHouseholds, IFNULL(multi_storey_fee_scale,0) as multiStoreyFeeScale," +
            "high_rise_area as highRiseArea, IFNULL(high_rise_buildingNum,0) as highRiseBuildingNum, IFNULL(high_rise_households,0) as highRiseHouseholds, IFNULL(high_rise_fee_scale,0) as highRiseFeeScale," +
            "small_high_rise_area as smallHighRiseArea, IFNULL(small_high_rise_buildingNum,0) as smallHighRiseBuildingNum, IFNULL(small_high_rise_households,0) as smallHighRiseHouseholds," +
            " IFNULL(small_high_rise_fee_scale,0) as smallHighRiseFeeScale,villa_area as villaArea, IFNULL(villa_buildingNum,0) as villaBuildingNum, IFNULL(villa_households,0) as villaHouseholds," +
            " IFNULL(villa_fee_scale,0) as villaFeeScale,dot_area as dotArea, IFNULL(dot_buildingNum,0) as dotBuildingNum, IFNULL(dot_households,0) as dotHouseholds, IFNULL(dot_fee_scale,0) as dotFeeScale," +
            "other_area as otherArea, IFNULL(other_buildingNum,0) as otherBuildingNum, IFNULL(other_households,0) as otherHouseholds, IFNULL(other_fee_scale,0) as otherFeeScale,rate_of_charge as rateOfCharge," +
            "actual_charge as actualCharge,ground_num as groundNum,IFNULL(ground_rental,0) as groundRental,IFNULL(ground_service_charge,0) as groundServiceCharge,ground_parking_fee as groundParkingFee," +
            "underground_num as undergroundNum, IFNULL(underground_rental,0) as undergroundRental, IFNULL(underground_service_charge,0) as undergroundServiceCharge," +
            "underground_parking_fee as undergroundParkingFee,other_income as otherIncome  FROM company_profit WHERE project_id=#{projectId}")
    ProfitVO detail(@Param(Common.PROJECT_ID) String projectId);
    /**
     * 根据id查询项目经营情况信息
     *
     * @param projectId 项目ID
     * @return projectId
     */
    @Select("SELECT id,main_business_income as mainBusinessIncome FROM company_profit WHERE project_id=#{projectId}")
    ProfitVO projectOperation(@Param(Common.PROJECT_ID) String projectId);

    /**
     * 新增物业费
     *
     * @param profit 物业费实体
     * @return 结果
     */
    @Insert("INSERT INTO company_profit(gmt_create,gmt_modified,main_business_income,public_income,profit,year,project_id,multi_storey_area," +
            "multi_storey_buildingNum,multi_storey_households,multi_storey_fee_scale,high_rise_area,high_rise_buildingNum,high_rise_households," +
            "high_rise_fee_scale,small_high_rise_area,small_high_rise_buildingNum,small_high_rise_households,small_high_rise_fee_scale," +
            "villa_area,villa_buildingNum,villa_households,villa_fee_scale,dot_area,dot_buildingNum,dot_households,dot_fee_scale,other_area," +
            "other_buildingNum,other_households,other_fee_scale,rate_of_charge,actual_charge,ground_num,ground_rental,ground_service_charge," +
            "ground_parking_fee,underground_num,underground_rental,underground_service_charge,underground_parking_fee,other_income)" +
            " VALUES(NOW(),NOW(),#{p.mainBusinessIncome},#{p.publicIncome},#{p.profit},#{p.year},#{p.projectId},#{p.multiStoreyArea}," +
            "#{p.multiStoreyBuildingNum},#{p.multiStoreyHouseholds},#{p.multiStoreyFeeScale},#{p.highRiseArea},#{p.highRiseBuildingNum},#{p.highRiseHouseholds}," +
            "#{p.highRiseFeeScale},#{p.smallHighRiseArea},#{p.smallHighRiseBuildingNum},#{p.smallHighRiseHouseholds},#{p.smallHighRiseFeeScale}," +
            "#{p.villaArea},#{p.villaBuildingNum},#{p.villaHouseholds},#{p.villaFeeScale},#{p.dotArea},#{p.dotBuildingNum},#{p.dotHouseholds},#{p.dotFeeScale},#{p.otherArea}," +
            "#{p.otherBuildingNum},#{p.otherHouseholds},#{p.otherFeeScale},#{p.rateOfCharge},#{p.actualCharge},#{p.groundNum},#{p.groundRental},#{p.groundServiceCharge}," +
            "#{p.groundParkingFee},#{p.undergroundNum},#{p.undergroundRental},#{p.undergroundServiceCharge},#{p.undergroundParkingFee},#{p.otherIncome})")
    int add(@Param("p") ProfitVO profit);

    /**
     * 编辑项目经营信息
     *
     * @param profit 经营信息
     * @return 结果
     */
    @Update("UPDATE company_profit SET main_business_income=#{p.mainBusinessIncome},public_income=#{p.publicIncome},profit=#{p.profit},multi_storey_area=#{p.multiStoreyArea}," +
            "multi_storey_buildingNum=#{p.multiStoreyBuildingNum},multi_storey_households=#{p.multiStoreyHouseholds},multi_storey_fee_scale=#{p.multiStoreyFeeScale}," +
            "high_rise_area=#{p.highRiseArea},high_rise_buildingNum=#{p.highRiseBuildingNum},high_rise_households=#{p.highRiseHouseholds},high_rise_fee_scale=#{p.highRiseFeeScale}," +
            "small_high_rise_area=#{p.smallHighRiseArea},small_high_rise_buildingNum=#{p.smallHighRiseBuildingNum},small_high_rise_households=#{p.smallHighRiseHouseholds}," +
            "small_high_rise_fee_scale=#{p.smallHighRiseFeeScale},villa_area=#{p.villaArea},villa_buildingNum=#{p.villaBuildingNum},villa_households=#{p.villaHouseholds}," +
            "villa_fee_scale=#{p.villaFeeScale},dot_area=#{p.dotArea},dot_buildingNum=#{p.dotBuildingNum},dot_households=#{p.dotHouseholds},dot_fee_scale=#{p.dotFeeScale}," +
            "other_area=#{p.otherArea},other_buildingNum=#{p.otherBuildingNum},other_households=#{p.otherHouseholds},other_fee_scale=#{p.otherFeeScale},rate_of_charge=#{p.rateOfCharge}," +
            "actual_charge=#{p.actualCharge},ground_num=#{p.groundNum},ground_rental=#{p.groundRental},ground_service_charge=#{p.groundServiceCharge},ground_parking_fee=#{p.groundParkingFee}," +
            "underground_num=#{p.undergroundNum},underground_rental=#{p.undergroundRental},underground_service_charge=#{p.undergroundServiceCharge}," +
            "underground_parking_fee=#{p.undergroundParkingFee},other_income=#{p.otherIncome} WHERE id=#{p.id}")
    int edit(@Param("p") ProfitVO profit);
}
